<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="wx/include :: header('订单详情')"/>
</head>
<body ontouchstart>
<!--主体-->
<header class="wy-header">
    <div class="wy-header-icon-back" onclick="javascript:history.go(-1)"><span></span></div>
    <div class="wy-header-title">订单详情</div>
</header>
<div class="weui-content">

    <div class="wy-media-box weui-media-box_text">
    <span class="weui-media-box__bd">
      <input type="hidden" id="orderId" th:value="${order.orderId}">
      <span style="font-size: 14px;" th:text="'订单号：' + ${order.orderId}"></span>
     <div class="weui-media-box_appmsg ord-pro-list" th:each="orderItem : ${orderItemList}">
        <div class="weui-media-box__hd"><a th:href="${'/wx/pro_info/' + orderItem.goodsId}"><img
                class="weui-media-box__thumb"
                th:src="${orderItem.goodsImage}" alt=""></a>
            <input type="hidden" id="goodsId" th:value="${orderItem.goodsId}">
        </div>
        <div class="weui-media-box__bd">
          <h1 class="weui-media-box__desc"><a href="javascript:;" class="ord-pro-link"
                                              th:text="${orderItem.goodsName}"></a></h1>
            <!--<p class="weui-media-box__desc">规格：<span>红色</span>，<span>23</span></p>-->
          <div class="clear mg-t-10">
            <div class="wy-pro-pri fl">¥<em class="num font-15" th:text="${orderItem.price}"></em></div>
            <div class="pro-amount fr">数量：<em th:text="${orderItem.num}"></em></div>
          </div>
        </div>
      </div>
    </div>
</div>
<div class="weui-panel">
    <div class="weui-panel__bd">
        <div class="weui-media-box weui-media-box_small-appmsg">
            <div class="weui-cells">
                <div class="weui-cell weui-cell_access" th:if="${order.paymentResult == '1'}">
                    <div class="weui-cell__bd weui-cell_primary">
                        <p class="font-14"><span class="mg-r-10">购买日期</span><span class="fr"
                                                                                  th:text="${#dates.format(order.paymentTime,'yyyy-MM-dd HH:mm:ss')}"></span>
                        </p>
                    </div>
                </div>
                <div class="weui-cell weui-cell_access">
                    <div class="weui-cell__bd weui-cell_primary">
                        <p class="font-14"><span class="mg-r-10">配送方式</span><span class="fr">自动开通</span></p>
                    </div>
                </div>
                <div class="weui-cell weui-cell_access" href="javascript:;">
                    <div class="weui-cell__bd weui-cell_primary">
                        <p class="font-14"><span class="mg-r-10">总金额</span><span class="fr txt-color-red">￥<em
                                class="num" th:text="${order.totalPrice}"></em></span></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="wy-media-box weui-media-box_text" th:if="${order.paymentResult != '1'}">
    <!--<div class="mg10-0 t-c">总金额：<span class="wy-pro-pri mg-tb-5">¥<em class="num font-20">296.00</em></span></div>-->
    <div class="mg10-0"><a href="javascript:;" class="weui-btn weui-btn_primary" onclick="wePayForCharge()">微信付款</a>
    </div>
</div>
</div>

<th:block th:include="wx/include :: footer"/>

<script>
    $('.exchange').on('click', function () {
        $.alert("活动还没有开通！");
    });

    function wePayForCharge() {
        var orderId = $("#orderId").val();
        var goodsId = $("#goodsId").val();
        $.post("/wx/checkRepeat?orderId=" + orderId + "&goodsId=" + goodsId, {}, function (resp) {
            if (resp.code === 0) {
                $.post("/ws/v2/api/pay/createOrder/" + orderId, {}, function (json) {
                    if (json.code === 0) {
                        var json = json.data;
                        WeixinJSBridge.invoke(
                            'getBrandWCPayRequest', {
                                "appId": json.appId,     		//公众号名称，由商户传入
                                "nonceStr": json.nonceStr, 		//随机串
                                "package": json.packageValue,
                                "paySign": json.paySign, 		//微信签名
                                "signType": "MD5",         		//微信签名方式：
                                "timeStamp": json.timeStamp      //时间戳，自1970年以来的秒数
                            },
                            function (res) {

                                if (res.err_msg === "get_brand_wcpay_request:ok") {
                                    window.location.href = '/wx/skip';
                                    // $.confirm("", "支付成功！", function () {
                                    //     // window.location.href = '/wx/orders'
                                    //   window.location.href = '/wx/skip'
                                    // }, function () {
                                    //     window.location.href = '/wx/orders'
                                    // });
                                } else if (res.err_msg === "get_brand_wcpay_request:cancel") {

                                } else {
                                    $.alert("支付失败" + res.err_msg);
                                }
                            }
                        );
                    } else {
                        $.alert(json.errorMessage);
                    }
                });
            } else {
                $.alert(resp.msg);
            }
        });
    }


    function onBridgeReady(data) {
        WeixinJSBridge.invoke('getBrandWCPayRequest', {
                "appId": data.appId, //公众号名称，由商户传入
                "timeStamp": data.timeStamp, //时间戳，自1970年以来的秒数
                "nonceStr": data.nonceStr, //随机串
                "package": data.package,
                "signType": data.signType, //微信签名方式：
                "paySign": data.paySign  //微信签名
            },
            function (res) {
                if (res.err_msg === "get_brand_wcpay_request:ok") {
                    document.location.reload();
                }
            });
    }

    function callpay(data) {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady,
                    false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady(data);
        }
    }
</script>

</body>
</html>
